package com.cy.pj.modules.service.impl;

import com.cy.pj.common.bo.PageObject;
import com.cy.pj.modules.mapper.SkuShopMapper;
import com.cy.pj.modules.service.ISkuShopService;
import com.cy.pj.modules.vo.SkuShopVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SkuShopServiceImpl implements ISkuShopService {

    @Autowired
    private SkuShopMapper skuShopMapper;

    @Value("${fz.pageHelper.pageSize}")
    private Integer pageSize;
    @Override
    public PageObject<SkuShopVo> selectSkuShopList(SkuShopVo skuShopVo, Integer pageCurrent) {
        //1.参数校验
        if (pageCurrent == null || pageCurrent < 1) {
            throw new IllegalArgumentException("页码值无效");
        }
        //2.设置分页参数
        String orderBy = "fsk_add_time desc,bid asc";
        Page<SkuShopVo> page = PageHelper.startPage(pageCurrent, pageSize, orderBy);
        //3.查询当前页记录
        List<SkuShopVo> list = skuShopMapper.selectSkuShopList(skuShopVo);
        return new PageObject<>(list, (int) page.getTotal(), page.getPages(), pageSize, pageCurrent);
    }
}
